# -*- coding:utf-8 -*-
# @Time : 21-8-3 下午4:44 
# @Author : zdy
# @File : TableView.py
# desc:
from importQT import *
class TableView(QTableView):
    sigMouseLeft =pyqtSignal()
    sigMouseRightMove = pyqtSignal()
    sigKeyUpDown = pyqtSignal()
    def __init__(self,parent):
        super(TableView, self).__init__(parent)

    def mouseReleaseEvent(self, event:QMouseEvent):
        QTableView.mouseReleaseEvent(self,event)
        if event.button() ==Qt.LeftButton:
            self.sigMouseLeft.emit()

    def mouseMoveEvent(self, e: QMouseEvent) -> None:
        if e.buttons() == Qt.RightButton:
            # 注意这里如果使用e.button()会一直返回0，表示产生事件的按钮；
            # 而e.buttons()表示当前按下的所有按钮状态
            self.sigMouseRightMove.emit()
        else:
            QTableView.mouseMoveEvent(self, e)

    def keyReleaseEvent(self, event) -> None:#若用keyPressEvent，每次更新的都是上一次的值
        if event.key() == Qt.Key_Down or event.key() == Qt.Key_Up:
            self.sigKeyUpDown.emit()
        super(TableView, self).keyReleaseEvent(event)



